package sopt.dev.activity;

import sopt.dev.R;
import sopt.dev.network.LoginRequest;
import sopt.dev.network.NetworkController;
import sopt.dev.network.NetworkRequest;
import sopt.dev.network.NetworkRequest.OnProcessCompletedListener;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class LoginActivity extends Activity implements OnClickListener {

	private EditText login_id;
	private EditText login_passwd;
	private LinearLayout layout01;
	private ProgressDialog pDialog;
	private Button button;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login_activity);
		login_id = (EditText) findViewById(R.id.id);
		login_passwd = (EditText) findViewById(R.id.passwd);
		button = (Button) findViewById(R.id.loginButton);
		button.setOnClickListener(this);
		layout01 = (LinearLayout) findViewById(R.id.layout01);
	}

	@Override
	public void onClick(View v) {
		loginProcess();
	}

	// 로그인 버튼이 클릭되면 수행되는 메서드
	public void loginProcess() {

		LoginRequest slr = new LoginRequest(login_id.getText().toString(), 
				login_passwd.getText().toString());

		NetworkController.getInstance().enqueue(slr);

		slr.setOnCompleteListener(new OnProcessCompletedListener() {

			@Override
			public void onCompleted(NetworkRequest request) {
			
				// login success
				String result = (String) request.getResult();
				if (result == "success") {
					startActivity(new Intent(LoginActivity.this, CityListActivity.class));
					// TODO
				}
				// login fail
				else {
					// TODO
				}
			}
		});


	}

}
